<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateCommissionRecordsTable extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     */
    public function change()
    {
        $table = $this->table('commission_records', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_unicode_ci']);
        $table->addColumn('user_id', 'integer', ['null' => false, 'comment' => '用户ID'])
            ->addColumn('from_user_id', 'integer', ['null' => false, 'comment' => '来源用户ID'])
            ->addColumn('order_id', 'string', ['limit' => 64, 'null' => false, 'comment' => '订单ID'])
            ->addColumn('amount', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0, 'comment' => '佣金金额'])
            ->addColumn('level', 'integer', ['limit' => 1, 'default' => 1, 'comment' => '佣金层级: 1-一代, 2-二代, 3-三代及以上'])
            ->addColumn('from_level', 'integer', ['limit' => 1, 'default' => 1, 'comment' => '来源用户等级: 1-V1, 2-V2, 3-V3'])
            ->addColumn('status', 'integer', ['limit' => 1, 'default' => 1, 'comment' => '状态: 0-无效, 1-有效'])
            ->addColumn('remark', 'string', ['limit' => 255, 'null' => true, 'comment' => '备注'])
            ->addColumn('create_time', 'timestamp', ['null' => true, 'comment' => '创建时间'])
            ->addColumn('update_time', 'timestamp', ['null' => true, 'comment' => '更新时间'])
            ->addIndex(['user_id'])
            ->addIndex(['from_user_id'])
            ->addIndex(['order_id'])
            ->create();
    }
} 